extends Node

var _playerDic={}
var activePlayerArr=[]

func getPlayer(uid):
	uid=str(uid)
	return _playerDic.get(uid,null)
func getActor(uid):
	uid=str(uid)
	var player=_playerDic.get(uid,null)
	if !player:
		return null
	var actor=player.actor
	return actor

func addPlayer(uid,uName):
	uid=str(uid)
	var player=getPlayer(uid) as Player
	if player:
		_activePlayer(player)
		return player
	player=Player.new()
	player.uid=uid
	player.uName=uName
	_activePlayer(player)
	_playerDic[uid]=player
	return player

func _process(delta):
	#删除角色的判定
	for player in activePlayerArr:
		(player as Player).removeTimer+=delta
	var needTime=100000000000 #多久没操作删除
	var num=activePlayerArr.size()
	if num<=50: #如果人少于50，就不自动删除
		pass
	elif num<=100:
		needTime=3*60
	elif num<=150:
		needTime=2*60
	elif num<=200:
		needTime=60
	elif num<=300:
		needTime=30
	elif num<=400:
		needTime=20
	elif num<=500:
		needTime=10
	elif num<=1000:
		needTime=5
	else:
		needTime=2
	var arr=activePlayerArr.duplicate()
	for player in arr:
		if player.removeTimer>=needTime:
			_unActivePlayer(player)
func _activePlayer(player):
	player.active()
	if !activePlayerArr.has(player):
		activePlayerArr.append(player)
	pass
func _unActivePlayer(player):
	player.unActive()
	activePlayerArr.erase(player)
